/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.utx.spot.timesync.protocol;

/**
 *
 */
public class NullClockController implements IClockController {

    private int serverToClientOffset;
    private int clientToServerOffset;
    private int timeError;
    private int propagationDelay;
    
    public NullClockController() {
        this.serverToClientOffset = 0;
        this.clientToServerOffset = 0;
        this.propagationDelay = 0;
        this.timeError = 0;
    }

    public void updateServerToClientOffset(long offset) {
        serverToClientOffset = (int)offset;
        timeError = serverToClientOffset - propagationDelay;
    }
    
    public void updateClientToServerOffset(long offset) {
        clientToServerOffset = (int)offset;
        propagationDelay = (serverToClientOffset + clientToServerOffset) / 2;
        timeError = serverToClientOffset - propagationDelay;
    }

    public void printState() {
        System.out.println("Null controller:");
        System.out.println("  server-client offset : " +serverToClientOffset);
        System.out.println("  client-server offset : " +clientToServerOffset);
        System.out.println("  propagation delay : "  + propagationDelay);
        System.out.println("  time error : " + timeError);
    }
}
